package com.xuanyuan.atlas.config;

import com.netflix.client.DefaultLoadBalancerRetryHandler;
import com.netflix.loadbalancer.AbstractLoadBalancer;
import com.netflix.loadbalancer.reactive.LoadBalancerCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.cloud.openfeign.support.SpringMvcContract;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import reactivefeign.cloud.CloudReactiveFeign;
import reactivefeign.webclient.WebReactiveFeign;

/**
 * @author LUOYUAN
 * @create 2020-05-14-12:00
 */
@Configuration
@Import(FeignClientsConfiguration.class)
public class WebReactiveFeignConfig {

    @Autowired
    SpringClientFactory springClientFactory;
/*
    @Bean
    public OVMReacticeFeign demo(){
        String serviceName = "CMP-OVMMGMT";
        OVMReacticeFeign client = CloudReactiveFeign.<OVMReacticeFeign>builder(WebReactiveFeign.builder())
                .setLoadBalancerCommandFactory(s -> LoadBalancerCommand.builder()
                        .withLoadBalancer(AbstractLoadBalancer.class.cast(springClientFactory.getLoadBalancer(serviceName)))
                        .withRetryHandler(new DefaultLoadBalancerRetryHandler(1, 1, true))

                        .build())
                .contract(new SpringMvcContract())
                .target(OVMReacticeFeign.class,  "http://" + serviceName);

        return client;
    }
*/

}